-- @owner: opentestcase023
-- @date: 2022/02/24
-- @testpoint: 更新src表中id3值之前触发设置des表中id3值为5

--step1:建表;expect:成功
drop table if exists t_trigger_src cascade;
drop table if exists t_trigger_des cascade;
create table t_trigger_src(id1 int, id2 int, id3 int) with (storage_type=ustore);
create table t_trigger_des(id1 int, id2 int, id3 int) with (storage_type=ustore);

--step2:更新src表中id3值之前触发设置des表中id3值为5;expect:成功
create or replace function tri_update_func() returns trigger as
$$
declare
begin
update t_trigger_des set id3=5;
return new;
end
$$ language plpgsql;
/
drop trigger if exists update_trigger on t_trigger_src;
create trigger update_trigger before update of id3 on t_trigger_src
for each statement
when(true)
execute procedure tri_update_func();
/
insert into t_trigger_src values(1,1,1),(2,2,2);
insert into t_trigger_des values(1,1,1),(2,2,2);
select * from t_trigger_des order by id1;
update t_trigger_src set id3=10;
select * from t_trigger_src order by id1;
select * from t_trigger_des order by id1;
update t_trigger_src set id2=10;
select * from t_trigger_src order by id1;
select * from t_trigger_des order by id1;
update t_trigger_src set id1=10;
select * from t_trigger_src order by id1;
select * from t_trigger_des order by id1;

--step3:清理环境;expect:成功
drop table if exists t_trigger_src cascade;
drop table if exists t_trigger_des cascade;